#include "ScoreCard.h"

std::string files[] = {"Zero.mesh","One.mesh","Two.mesh","Three.mesh","Four.mesh","Five.mesh","Six.mesh","Seven.mesh","Eight.mesh","Nine.mesh"};
std::string toApp[] = {"0","1","2","3","4","5","6","7","8","9"};

ScoreCard::ScoreCard(char* name, Ogre::SceneManager* sm, Ogre::SceneNode* toAddTo){
	score = 0;
	Ogre::Entity *meshes[NUMDIGITS][10];
	int i;
	int j;
	for(i = 0; i<10; i++){
		double startx = 0;
		double starty = 0;
		double startz = 0;
		double dx = 80;
		double x = startx;
		for(j = 0; j<NUMDIGITS; j++){
			std::string newName(name);
			newName.append(toApp[j]);
			newName.append(toApp[i]);
			meshes[j][i] = sm->createEntity(newName, files[i]);
			Ogre::SceneNode* myNode = toAddTo->createChildSceneNode();
			myNode->setScale(40,40,40);
			myNode->setPosition(x,starty,startz);
			myNode->attachObject(meshes[j][i]);
			if(i!=0){
				myNode->setVisible(0);
			}
			digits[j][i] = myNode;
			x = x - dx;
		}
	}
}

void ScoreCard::setScore(int newScore){
	int i;
	score = newScore;
	int tscore = newScore;
	for(i = 0; i<NUMDIGITS; i++){
		int j;
		for(j=0;j<10;j++){
			digits[i][j]->setVisible(0);
		}
		int toMakeVis = tscore % 10;
		digits[i][toMakeVis]->setVisible(1);
		tscore = tscore / 10;
	}
}

void ScoreCard::addScore(int toAdd){
	setScore(score + toAdd);
}

void ScoreCard::updateState(){
	//addScore(1);
}

void ScoreCard::alertToInput( const InputSet& input ){}

void ScoreCard::draw( Engine* game ){
}
